<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>

<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>病房管理</title>
<style type="text/css">
.cc_item {
	padding: 10px;
}
</style>
</head>
<body>
	<script type="text/javascript">
	
		function chkmaxsms(vobj1,vmax)   {  
			 var str=vobj1.value;  
			 var strlen=str.length;
			 var vv=vmax-strlen;
			if(strlen>vmax)   {  
			  $("#cc_show_dnameshu")
				.html("你已经输入了："+vmax+"个字，还可以输入0个字！");
			  $.messager.alert("提示", "您已经超出该文本的输入范围，系统将只截取有效范围内的字符！");
			  $("#cc_input_dname").val(vobj1.value=str.substr(0,vmax));
			}else{
				$("#cc_show_dnameshu")
				.html("你已经输入了："+strlen+"个字，还可以输入"+vv+"个字！");
				
			}
		} 
		$(function() {
			var  shenpi_staffId = $("#tontyiStaffId").html();
			//onChange
			$("#cc_advice_elePerid").combogrid({
				url : 'tocc_queryBypadoctorid',
				queryParams : {
					padoctorid : shenpi_staffId
				}
			});
			//cc_toqueryBydoctorid
			$("#cc_doctor_advice_dg").datagrid({
				url:'cc_toqueryBydoctorid',
				queryParams : {
					doctorid : shenpi_staffId
				}
			});
			$("#cc_advice_save").linkbutton({
				onClick:function(){
					var vv=$("#cc_doctor_advice_id").val();
					var dname= $("#cc_input_dname").val();
					if(dname.length>0){
						if(vv.length>0){
							$("#cc_doctor_advice_printstaff").val(shenpi_staffId);
							$("#cc_doctor_advice_form").form("submit", {
								url:'tocc_updateCcDoctorAdvice',
								 onSubmit: function(param){
									 return $(this).form('validate');
								 }, 
								success : function(data) {
									var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$(this).form("clear");
									$("#cc_doctor_advice_dg").datagrid("reload");
								}
							});
						}else{
							$("#cc_doctor_advice_printstaff").val(shenpi_staffId);
							$("#cc_doctor_advice_form").form("submit", {
								url:'tocc_addCcDoctorAdvice',
								 onSubmit: function(param){
									 return $(this).form('validate');
								 }, 
								success : function(data) {
									var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$(this).form("clear");
									$("#cc_doctor_advice_dg").datagrid("reload");
								}
							});
						} 
					}else{
						$.messager.alert("提示", "请输入报告内容！");
					}
				}
			});
			//cc_doctor_advice_id
			$("#cc_doctor_advice_show_btn").linkbutton({
				onClick:function(){
					var rows=$("#cc_doctor_advice_dg").datagrid("getSelections");
					if(rows.length==1){
						//alert(rows[0].daId);
						$("#cc_doctor_advice_id").val(rows[0].daId);
						if(rows[0].staffid!=shenpi_staffId){
							$.messager.alert("提示", "系统检测到此条报告非你本人添加，所以你只能阅读！");
							$("#cc_advice_save").linkbutton("disabled",true);
						}
						$.getJSON("tocc_queryByOne", {"adid" : rows[0].daId}, function(data) {
							$("#cc_doctor_advice_form").form("load", data);
						});
					}else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
				}
			});
			$("#cc_doctor_advice_delete_btn").linkbutton({
				onClick:function(){
					$.messager.confirm("提示", "确定要取消吗？", function(v){
						if(v){
							//获取所有选中的编号
							var rows = $("#cc_doctor_advice_dg").datagrid("getSelections");
							//var doctorid= $("#cc_hpdoctorid").textbox("getValue");
							//将编号保存到数组中
							var date = new Date();
						    var seperator1 = "/";
						    var month = date.getMonth() + 1;
						    var strDate = date.getDate();
						    if (month >= 1 && month <= 9) {
						        month = "0" + month;
						    }
						    if (strDate >= 0 && strDate <= 9) {
						        strDate = "0" + strDate;
						    }
						    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		  
							var arr = [];
							
							for(var i = 0; i < rows.length; i ++){
								if(currentdate==rows[i].printdate){
									arr.push(rows[i].daId);
								}
							}
							//用form提交
							$('<form>').form('submit', {
							    url:'tocc_deleteCcDoctorAdvice',
							    onSubmit: function(param){
							    	param.list=arr;
							    },
							    success:function(data){
							    	var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$("#cc_doctor_advice_id").val("");
									$("#cc_doctor_advice_dg").datagrid("reload");
							    }
							});
						}
					});
				}
			});
			$("#cc_doctor_advice_canlen_btn").linkbutton({
				onClick:function(){
					$("#cc_doctor_advice_dg").datagrid({
						url:'cc_toqueryBydoctorid',
						queryParams : {
							doctorid : shenpi_staffId
						}
					});
				}
			});
			$('#cc_doctor_advice_searchbox_btn').searchbox({
			    searcher:function(value,name){
			    	if(name=="患者姓名"){
			    		$("#cc_doctor_advice_dg").datagrid({
				    		url:'tocc_queryByPname',
				    		queryParams: {
				    			pname: value
				    		}
				    	});
			    	}
			    }
			});
		});
		function cc_doctorAdvicerowStlye(index,row){
			//alert(new Date());
			var date = new Date();
		    var seperator1 = "/";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    if (row.printdate==currentdate){
				return 'background-color:#CCFF99;color:red;';
				
			}
		}
	</script>
	<div style="height: 40%">
		<table id="cc_doctor_advice_dg" class="easyui-datagrid"
			data-options="
					fitColumns:true,
					fit:true,
					striped:true,
					rownumbers: true,
					border:false ,
					toolbar: '#cc_doctor_advice_btn',
					pagination:true,
					pageSize: 4,
					pageList:[4,8,12,24],
					rowStyler: cc_doctorAdvicerowStlye
				">
			<thead>
				<tr>
					<th data-options="field:'daId', width:'5%',checkbox:true">ID</th>
					<th data-options="field:'pname', width:'20%'">患者姓名</th>
					<th data-options="field:'gename', width:'20%'">所住病房</th>
					<th data-options="field:'departmentName', width:'19%'">所属科室</th>
					<th data-options="field:'staffid',hidden:true, width:'20%'">报告人id</th>
					<th data-options="field:'staffName', width:'20%'">报告人</th>
					<th data-options="field:'printdate', width:'20%'">报告日期</th>
	
				</tr>
			</thead>
		</table>
	</div>
	<div id="cc_doctor_advice_btn">
		
		<a id="cc_doctor_advice_show_btn" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit',plain:true">查看报告信息</a>
		<a id="cc_doctor_advice_delete_btn" class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">删除报告</a>
		<a id="cc_doctor_advice_canlen_btn" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input id="cc_doctor_advice_searchbox_btn" class="easyui-searchbox"
			data-options="menu:'#cc_doctor_adviceee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_doctor_adviceee" style="width: 90px">
		<div date-options="name:'name'">患者姓名</div>
	</div>
<div id="cc_doctor_advice_tab" class="easyui-tabs" style="width:100%; margin-top: 15px;"
				data-options="plain:true,narrow:true">
<div title="撰写报告" data-options="iconCls:'icon-baogao'">
<form id="cc_doctor_advice_form" action="" method="post">
	
		<table style="width:100%;font-size:12px;background: rgb(236,243,255); padding: 10px; border-radius: 5px;">
			<tr>
				<td>
				<div style="display: none">
					<input id="cc_doctor_advice_id" name="daId">
					<input id="cc_doctor_advice_printstaff" name="printstaff">
				</div>
				<select id="cc_advice_elePerid" name="elePerid"
					class="easyui-combogrid"
					data-options="
							labelAlign:'right', width: 300,
							label:'患者:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '患者不能为空',
							panelWidth: '223',
							idField: 'patientid',
							textField: 'pname',
							columns: [[
								{field: 'patientid', title: '患者编号', width: 80},
								{field: 'icid', title: '患者IC卡号', width: 80},
								{field: 'pname', title: '患者姓名', width: 60},
							]]
						"></select></td>
			</tr>
			<tr>
				<td>
					<div style="margin-left:23px;padding: 0px">
						<span style="position:relative; bottom:150px;left:2px">报告内容:</span>
						<textarea id="cc_input_dname" name="adName" style="height:155px;
							width:71%;margin-left:3px;
							border-top-right-radius:5px;
							border-top-left-radius:5px;
							border-bottom-right-radius:5px;
							border-bottom-left-radius:5px;"
						 onkeyup="javascript:chkmaxsms(this,'999')"></textarea>
						<a id="cc_advice_save"  style="margin-bottom:10px"  class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">提交报告</a>
					</div>
					<div id="cc_show_dnameshu" style="margin-left:363px;margin-top: 0px;padding: 0px;color:#666666;position:relative; bottom:10px;">
						你已经输入了：0个字，还可以输入999个字！
					</div>
				</td>
			</tr>
		</table>
</form>
</div>
</div>
</body>
</html>